//
//  AppTVImageCCell.m
//  classicFilms
//
//  Created by 刘继丹 on 17/3/14.
//  Copyright © 2017年 Stefan Arn. All rights reserved.
//

#import "AppTVImageCCell.h"
#import "KeyHeader.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>

@interface AppTVImageCCell()

@property(nonatomic, strong) UIImageView *mBackView;

@end

@implementation AppTVImageCCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.imageView];
        [self.imageView addSubview:self.mBackView];
        [self.contentView addSubview:self.playbtn];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    _imageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    _mBackView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    UIImage *image = [UIImage imageNamed:@"btn_play"];
    _playbtn.frame = CGRectMake(self.frame.size.width/2-image.size.width/2.f, self.frame.size.height/2-image.size.height/2.f, image.size.width, image.size.height);
}

-(void)setImageStr:(NSString *)imageStr{
    if (_imageStr != imageStr) {
        _imageStr = imageStr;
    }
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:_imageStr]];
}

-(UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]init];
        _imageView.adjustsImageWhenAncestorFocused = YES;
        _imageView.contentMode = UIViewContentModeScaleAspectFit;

    }
    return _imageView;
}

-(UIImageView *)mBackView{
    if (!_mBackView) {
        _mBackView = [[UIImageView alloc]init];
        _mBackView.adjustsImageWhenAncestorFocused = YES;
        _mBackView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
    }
    return _mBackView;
}

-(UIButton *)playbtn{
    if (!_playbtn) {
        _playbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_playbtn setImage:[UIImage imageNamed:@"btn_play"] forState:UIControlStateNormal];
        _playbtn.hidden = YES;
    }
    return _playbtn;
}

#pragma mark UIFocusEnvironment methods

@end
